home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
CPU_MEMO
/
3468.ZIP
/
POPUP.ZIP
/
ADJALLOC.C
next >
Wrap
C/C++ Source or Header
|
1988-06-30
|
4KB
|
94 lines
/*****************************************************************************
* Module : ADJALLOC.C *
*----------------------------------------------------------------------------*
* Program : ADJALLOC.EXE *
*----------------------------------------------------------------------------*
* Author : M.R.Watson. Copyright (c) M.R.Watson 1988 *
*----------------------------------------------------------------------------*
* Last Updated : 30/06/88 *
*----------------------------------------------------------------------------*
* Synopsis *
* ======== *
* Adjusts the Maximum paragraph allocation of an EXE file, depending on the *
* minimum allocation. Usage is ADJALLOC [Filename] [increase in hex] *
* This is intended to be used with makefiles for TSR's with programs *
* produced by Microsoft C. It directly modifies the EXE header! *
*****************************************************************************/
#include <stdio.h>
#include <standard.h>
struct ExeStr /* Structure of EXE file header */
{
WORD signature ;
WORD LengthMod512 ;
WORD LengthDiv512 ;
WORD RelocCount ;
WORD HeaderDiv16 ;
WORD MinPara ;
WORD MaxPara ;
WORD SegDisp ;
WORD SPstart ;
WORD CheckSum ;
WORD IPstart ;
WORD CodeSegDisp ;
WORD FirstReloc ;
};
/******************************************************************************
* MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN *
******************************************************************************/
main( argc, argv )
int argc ;
char *argv[] ;
{
char filename[81];
FILE *fp ;
WORD adjustment ;
struct ExeStr header;
if ( argc != 3 )
{
printf("\nUsage: ADJALLOC [Filename] [adjustment]\n\n");
printf("Where [Filename] is the name of the EXE file to have it's maximum\n");
printf(" memory allocation adjusted. (If no extent is given, \"EXE\" is used.)\n");
printf("and [adjustment] will be used to set the maximum paragraph allocation\n");
printf(" as follows: Max alloc = Min alloc + adjustment.\n");
printf(" The adjustment must be given in hex.\n\n");
}
strcpy( filename, argv[1] );
if ( strchr( filename, '.' ) == NULL )
strcat( filename, ".EXE" );
adjustment = strtol( argv[2], NULL, 16 );
if ( (fp = fopen( filename, "r+b" )) == NULL )
{
printf("\nError : Can't open %s\n", filename );
exit(FAIL);
}
if ( fread( &header, sizeof(header), 1, fp ) != 1 )
{
printf("Error - %s is a bad EXE file.\n", filename );
exit(FAIL);
}
rewind(fp);
header.MaxPara = header.MinPara + adjustment ;
if ( fwrite( &header, sizeof(header), 1, fp ) != 1 )
{
printf("Error writing to %s - file may be corrupt!\n");
exit(FAIL);
}
fclose(fp);
exit(SUCCEED);
}